home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / c / qtools0.2-src.lha / src / libqdisplay / draw-orig16.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-10  |  4.5 KB  |  169 lines

  1. #ifdef    USE_ZBUFFER
  2. #define    inc()        { u += du; v += dv; w += dw; }
  3. #define    fill(pel, z) { *pBuffer++ = (pel); *zBuffer++ = (unsigned short int)(z); }
  4. #else
  5. #define    inc()        { u += du; v += dv; }
  6. #define    fill(pel, z) { *pBuffer++ = (pel); }
  7. #endif
  8.  
  9. #ifdef    USE_ZBUFFER
  10. unsigned short int *draw_affine16(int n, unsigned short int *pBuffer, unsigned short int *zBuffer, int u, int v, int w, int du, int dv, int dw)
  11. #else
  12. unsigned short int *draw_affine16(int n, unsigned short int *pBuffer, int u, int v, int du, int dv)
  13. #endif
  14. {
  15.   if (textureType == WALL_TYPE) {
  16.     while (n--) {
  17.       int iu = u >> 16;
  18.       int iv = ((v >> (16 - MAX_LOGY)) & MAX_MASKX) + textureRow;
  19.  
  20. #ifdef CALCULATE_PIXELDRAW
  21.       pixelDraw++;
  22.       if (*pBuffer)
  23.     pixelOverdraw++;
  24. #endif
  25.  
  26.       fill(texture.hicolor[multMuls[iv] + iu], w);
  27.       inc();
  28.     }
  29.   }
  30.   else if (textureType == SKY_TYPE) {
  31.     /* TODO: skies */
  32.     while (n--) {
  33.       int iu;
  34.       int iv;
  35.       unsigned short int pel, sum;
  36.  
  37. #ifdef CALCULATE_PIXELDRAW
  38.       pixelDraw++;
  39.       if (*pBuffer)
  40.     pixelOverdraw++;
  41. #endif
  42.  
  43.       iu = ((u >> 8) + skyMovementX1) & 0x00007F00;
  44.       iv = ((v >> 16) + skyMovementY1) & 0x0000007F;
  45.       sum = texture.hicolor[iu + iv + 0x80];
  46.       iu = ((u >> 8) + skyMovementX2) & 0x00007F00;
  47.       iv = ((v >> 16) + skyMovementY2) & 0x0000007F;
  48.       if ((pel = texture.hicolor[iu + iv]))
  49.     sum = pel;
  50.  
  51.       fill(sum, 0xFFFF);
  52.       inc();
  53.     }
  54.   }
  55.   else {
  56.     while (n--) {
  57. #ifndef    FAST_WARP
  58.       int iv = ((v + (swim_v[((u >> textureShift2) & 0xff)] >> textureMip)) >> 16) & textureMask2;
  59.       int iu = ((u + (swim_u[((v >> textureShift2) & 0xff)] >> textureMip)) >> textureShift1) & textureMask1;
  60. #else
  61.       int iv = ((v + swim_v[(u >> 16)]) >> 16) & textureMask2;
  62.       int iu = ((u + swim_u[(v >> 16)]) >> textureShift1) & textureMask1;
  63. #endif
  64.  
  65.       fill(pretransp(texture.hicolor[iu + iv], *pBuffer), w);
  66.       inc();
  67.     }
  68.   }
  69.   return pBuffer;
  70. }
  71.  
  72. /* given a span (x0,y)..(x1,y), draw a perspective-correct span for it */
  73. /*
  74.  * the zbuffer is interesting for dynamic model-draw etc.
  75.  * the buffers values (1/z) are all under 0, we can try to
  76.  * store them as 16bit-wide-fraction
  77.  *
  78.  * while(n--) {
  79.  *   *zbuf++ = (unsigned short int)(w); / we need only the lower part /
  80.  *   w += dw;
  81.  * }
  82.  *
  83.  */
  84. void draw_span16(int y, int sx, int ex)
  85. {
  86.   float w0, w1;
  87.   float v0, v1;
  88.   float u0, u1;
  89.  
  90. #ifdef    USE_ZBUFFER
  91.   int w, dw;                            /* 1/zbuffer */
  92. #endif
  93.   int v, dv;
  94.   int u, du;
  95.   int slen, rlen, len, end;
  96.  
  97.   unsigned short int *pBuffer = localDim.frameBuffer + multRows[y] + sx;
  98.  
  99. #ifdef    USE_ZBUFFER
  100.   unsigned short int *zBuffer = localDim.zBuffer + multRows[y] + sx;
  101. #endif
  102.   float prew = tmap[6] + y * tmap[8];
  103.   float prev = tmap[3] + y * tmap[5];
  104.   float preu = tmap[0] + y * tmap[2];
  105.  
  106.   /* compute (u,v) at left end */
  107.   w0 = 1 / (prew + sx * tmap[7]);                /* 1/zbuffer */
  108.   v0 = (prev + sx * tmap[4]) * w0;
  109.   u0 = (preu + sx * tmap[1]) * w0;
  110.  
  111.   len = ex - sx;
  112.   for (slen = len >> SUBDIV_SHIFT; slen > 0; slen--) {
  113. #ifdef    USE_ZBUFFER
  114.     w = FLOAT_TO_FIX(w0);                    /* 1/zbuffer */
  115. #endif
  116.     v = FLOAT_TO_FIX(v0);
  117.     u = FLOAT_TO_FIX(u0);
  118.  
  119.     end = sx + SUBDIV;
  120.     w1 = 1 / (prew + end * tmap[7]);
  121.     v1 = (prev + end * tmap[4]) * w1;
  122.     u1 = (preu + end * tmap[1]) * w1;
  123.  
  124. #ifdef    USE_ZBUFFER
  125.     dw = (FLOAT_TO_FIX(v1) - w) >> SUBDIV_SHIFT;        /* 1/zbuffer */
  126. #endif
  127.     dv = (FLOAT_TO_FIX(v1) - v) >> SUBDIV_SHIFT;
  128.     du = (FLOAT_TO_FIX(u1) - u) >> SUBDIV_SHIFT;
  129.  
  130. #ifdef    USE_ZBUFFER
  131.     pBuffer = draw_affine16(SUBDIV, pBuffer, zBuffer, u, v, w, du, dv, dw);
  132.     zBuffer += SUBDIV;
  133. #else
  134.     pBuffer = draw_affine16(SUBDIV, pBuffer, u, v, du, dv);
  135. #endif
  136.     sx = end;
  137.  
  138. #ifdef    USE_ZBUFFER
  139.     w0 = w1;                            /* 1/zbuffer */
  140. #endif
  141.     v0 = v1;
  142.     u0 = u1;
  143.   }
  144.  
  145. #ifdef    USE_ZBUFFER
  146.   w = FLOAT_TO_FIX(w0);                        /* 1/zbuffer */
  147. #endif
  148.   v = FLOAT_TO_FIX(v0);
  149.   u = FLOAT_TO_FIX(u0);
  150.   if ((rlen = (len & SUBDIV_MASK) - 1)) {            /* a) do not calc if only draw 1 pixel */
  151.     end = sx + rlen;
  152.     w1 = 1 / (prew + end * tmap[7]);
  153.     v1 = (prev + end * tmap[4]) * w1;
  154.     u1 = (preu + end * tmap[1]) * w1;
  155.  
  156. #ifdef    USE_ZBUFFER
  157.     dw = FLOAT_TO_FIX((w1 - w0) / rlen);            /* 1/zbuffer */
  158. #endif
  159.     dv = FLOAT_TO_FIX((v1 - v0) / rlen);
  160.     du = FLOAT_TO_FIX((u1 - u0) / rlen);
  161.   }
  162.   /* a) but draw that pixel surely */
  163. #ifdef    USE_ZBUFFER
  164.   draw_affine16(rlen + 1, pBuffer, zBuffer, u, v, w, du, dv, dw);    /* for the last pixel the du and dv are thrown away */
  165. #else
  166.   draw_affine16(rlen + 1, pBuffer, u, v, du, dv);        /* for the last pixel the du and dv are thrown away */
  167. #endif
  168. }
  169.